/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.Admin;

import java.util.List;
import javax.swing.table.DefaultTableModel;
import pojo.*;
import dao.*;
import java.util.Vector;

/**
 *
 * @author Dang Nhung
 */
public class Admin_RoomManage extends javax.swing.JPanel {

    private DefaultTableModel model = null;
    private String arr_trash[] = {"Không hoạt động", "Hoạt động"};
    List<Phongchieu> phongChieus = null;
    /**
     * Declare string constant
     */
    private final String ERR_LIST_EMPTY = "Room list is empty";
    private final String ERR_SELECTED_ROOM_EMPTY = "Selected Room  is empty";
    private final String LABEL_SAVE = "Save";
    private final String LABEL_UPDATE = "Update";
    private final String LABEL_ADD = "Add";
    private final String LABEL_EMPTY = "";

    /**
     * Creates new form ThemPhongChieu
     */
    public Admin_RoomManage() {
        initComponents();
        initStateComponents();
        LoadDBJTable();
    }

    /*
     * Clean Jtextfield and selection
     */
    private void clearTextFields() {
        this.jtxtcodeid.setText(LABEL_EMPTY);
        this.jtxtroomname.setText(LABEL_EMPTY);
        this.jtxtquantitiesofseat.setText(LABEL_EMPTY);
        this.jtxtquantitiesofseatrow.setText(LABEL_EMPTY);
        this.jcbroomstate.setSelectedIndex(1);
        this.jtblistofroom.clearSelection();
    }

    /**
     * Update by hnmtuan on 23/04/2012
     * Init state of components
     */
    private void initStateComponents() {
        // Disable all text fields
        this.jtxtcodeid.setEnabled(false);
        this.jtxtroomname.setEnabled(false);
        this.jtxtquantitiesofseat.setEnabled(false);
        this.jtxtquantitiesofseatrow.setEnabled(false);
        this.jcbroomstate.setEnabled(false);

        // Disable all button except Add room button
        this.jbtnreset.setEnabled(false);
        this.jbtnaddroom.setEnabled(true);
        this.jbtnupdateroom.setEnabled(false);
        this.jbtndeleteroom.setEnabled(false);
        this.jbtncancel.setEnabled(false);
     

        // Set text all
        this.jbtnaddroom.setText(LABEL_ADD);
        this.jbtnupdateroom.setText(LABEL_UPDATE);

        // Remove selected row
        this.jtblistofroom.clearSelection();
        
        
    }

    /**
     * Update by hnmtuan on 23/04/2012
     * selected state of components while selected row in jTable
     */
    private void selectedStateComponents() {
        // Disable all text fields
        this.jtxtcodeid.setEnabled(false);
        this.jtxtroomname.setEnabled(false);
        this.jtxtquantitiesofseat.setEnabled(false);
        this.jtxtquantitiesofseatrow.setEnabled(false);
        

        // Enable all button except Add room button
        this.jbtnreset.setEnabled(true);
        this.jbtnaddroom.setEnabled(true);
        this.jbtnupdateroom.setEnabled(true);
        this.jbtndeleteroom.setEnabled(true);
        this.jbtncancel.setEnabled(true);
    }

    /**
     * Update by hnmtuan on 23/04/2012
     * update state of components while click update button
     */
    private void updateStateComponents() {
        // Enable all text fields
        this.jtxtcodeid.setEnabled(true);
        this.jtxtroomname.setEnabled(true);
        this.jtxtquantitiesofseat.setEnabled(true);
        this.jtxtquantitiesofseatrow.setEnabled(true);

        // Enable all button except Add room button
        this.jbtnreset.setEnabled(true);
        this.jbtnaddroom.setEnabled(false);
        this.jbtnupdateroom.setEnabled(true);
        this.jbtndeleteroom.setEnabled(false);
        this.jbtncancel.setEnabled(true);

        // Change label of update button to save
        this.jbtnupdateroom.setText(LABEL_SAVE);
    }

    /**
     * Update by hnmtuan on 23/04/2012
     * Successfully update state of components while update finished
     */
    private void updateSuccessStateComponents() {
        // Rollback init state
        initStateComponents();

        // Change label of update button to update
        this.jbtnupdateroom.setText(LABEL_UPDATE);
    }

    /**
     * Update by hnmtuan on 23/04/2012
     * Add state of components while add finished
     */
    private void addStateComponents() {
        // Enable all text fields
        this.jtxtcodeid.setEnabled(true);
        this.jtxtroomname.setEnabled(true);
        this.jtxtquantitiesofseat.setEnabled(true);
        this.jtxtquantitiesofseatrow.setEnabled(true);
        this.jcbroomstate.setEnabled(true);

        // Enable all button except Add room button
        this.jbtnreset.setEnabled(true);
        this.jbtnaddroom.setEnabled(true);
        this.jbtnupdateroom.setEnabled(false);
        this.jbtndeleteroom.setEnabled(false);
        this.jbtncancel.setEnabled(true);

        // Flush text
        clearTextFields();

        // Change label of update button to save
        this.jbtnaddroom.setText(LABEL_SAVE);
    }

    private void addSuccessStateComponents() {
        // Rollback init state
        initStateComponents();

        // Change label of update button to update
        this.jbtnaddroom.setText(LABEL_ADD);
    }

    final public void LoadDBJTable() {
        model = (DefaultTableModel) jtblistofroom.getModel();
        model.getDataVector().clear(); // Empty data into JTable
        try {
            phongChieus = PhongChieuDAO.getPhongChieus();
            int count = 0;
            for (Phongchieu phongchieu : phongChieus) {
                Vector v = new Vector();
                v.addElement(++count);
                v.addElement(phongchieu.getCodePhong());
                v.addElement(phongchieu.getTenPhong());
                v.addElement(arr_trash[phongchieu.getTrangThai()]);
                model.addRow(v);
                v = null;
            }
            jtblistofroom.setModel(model);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        finally {
            try {
                PhongChieuDAO.closeCurrentSession(); // Must close at here, throw LazyExceptions
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jpnroomanage = new javax.swing.JPanel();
        jlbcodeid = new javax.swing.JLabel();
        jlbroomname = new javax.swing.JLabel();
        jlbquantitiesofseat = new javax.swing.JLabel();
        jlbquantitiesofseatline = new javax.swing.JLabel();
        jtxtcodeid = new javax.swing.JTextField();
        jtxtroomname = new javax.swing.JTextField();
        jtxtquantitiesofseat = new javax.swing.JTextField();
        jtxtquantitiesofseatrow = new javax.swing.JTextField();
        jbtnaddroom = new javax.swing.JButton();
        jbtnreset = new javax.swing.JButton();
        jbtncancel = new javax.swing.JButton();
        jbtnupdateroom = new javax.swing.JButton();
        jbtndeleteroom = new javax.swing.JButton();
        jlbroomstate = new javax.swing.JLabel();
        jcbroomstate = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jlblistofrooms = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtblistofroom = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jlbsearchroom = new javax.swing.JLabel();
        jchbsearchbyname = new javax.swing.JCheckBox();
        jchbsearchbycodeid = new javax.swing.JCheckBox();
        jbtnsearch = new javax.swing.JButton();
        jbtnshowall = new javax.swing.JButton();
        jtxttypethecodeid = new javax.swing.JTextField();
        jtxttypethename = new javax.swing.JTextField();

        jpnroomanage.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jlbcodeid.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbcodeid.setText("Code ID");

        jlbroomname.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbroomname.setText("Room's Name");

        jlbquantitiesofseat.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbquantitiesofseat.setText("Quantities of Seat");

        jlbquantitiesofseatline.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbquantitiesofseatline.setText("Quantities of Seat Line");

        jbtnaddroom.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnaddroom.setText("Add");
        jbtnaddroom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnaddroomActionPerformed(evt);
            }
        });

        jbtnreset.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnreset.setText("Reset");
        jbtnreset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnresetActionPerformed(evt);
            }
        });

        jbtncancel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtncancel.setText("Cancel");
        jbtncancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtncancelActionPerformed(evt);
            }
        });

        jbtnupdateroom.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnupdateroom.setText("Update");
        jbtnupdateroom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnupdateroomActionPerformed(evt);
            }
        });

        jbtndeleteroom.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtndeleteroom.setText("Delete");
        jbtndeleteroom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtndeleteroomActionPerformed(evt);
            }
        });

        jlbroomstate.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbroomstate.setText("Room's State");

        jcbroomstate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Không hoạt động\t", "Hoạt động", " " }));

        javax.swing.GroupLayout jpnroomanageLayout = new javax.swing.GroupLayout(jpnroomanage);
        jpnroomanage.setLayout(jpnroomanageLayout);
        jpnroomanageLayout.setHorizontalGroup(
            jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnroomanageLayout.createSequentialGroup()
                .addGap(96, 96, 96)
                .addGroup(jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbroomname, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlbquantitiesofseat, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlbquantitiesofseatline, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlbcodeid, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlbroomstate, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(46, 46, 46)
                .addGroup(jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jtxtquantitiesofseat, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtroomname, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtcodeid, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtquantitiesofseatrow)
                    .addComponent(jcbroomstate, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnroomanageLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbtnreset, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnaddroom, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnupdateroom, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtndeleteroom, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtncancel, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(117, 117, 117))
        );
        jpnroomanageLayout.setVerticalGroup(
            jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnroomanageLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbcodeid)
                    .addComponent(jtxtcodeid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbroomname)
                    .addComponent(jtxtroomname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbquantitiesofseat)
                    .addComponent(jtxtquantitiesofseat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtquantitiesofseatrow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbquantitiesofseatline))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlbroomstate)
                    .addComponent(jcbroomstate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(jpnroomanageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jbtncancel)
                    .addComponent(jbtndeleteroom)
                    .addComponent(jbtnupdateroom)
                    .addComponent(jbtnreset)
                    .addComponent(jbtnaddroom))
                .addContainerGap(44, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jlblistofrooms.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblistofrooms.setText("List Of Rooms");

        jtblistofroom.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "STT", "Code ID", "Room's Name", "Room's State"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jtblistofroom.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtblistofroomMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtblistofroom);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jlblistofrooms, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jlblistofrooms, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(270, 270, 270))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

        jlbsearchroom.setFont(new java.awt.Font("Tahoma", 3, 12)); // NOI18N
        jlbsearchroom.setText("Search Room");

        jchbsearchbyname.setText("By Name");

        jchbsearchbycodeid.setText("By Code ID");

        jbtnsearch.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnsearch.setText("Search");

        jbtnshowall.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnshowall.setText("Show All");

        jtxttypethecodeid.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jtxttypethecodeid.setText("Type the code id ...");

        jtxttypethename.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jtxttypethename.setText("Type the name...");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jlbsearchroom, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jchbsearchbycodeid)
                    .addComponent(jchbsearchbyname))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxttypethename)
                    .addComponent(jtxttypethecodeid, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jbtnsearch)
                .addGap(18, 18, 18)
                .addComponent(jbtnshowall)
                .addGap(40, 40, 40))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbtnsearch)
                            .addComponent(jbtnshowall)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jchbsearchbyname)
                            .addComponent(jtxttypethename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jchbsearchbycodeid)
                            .addComponent(jtxttypethecodeid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jlbsearchroom)))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpnroomanage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jpnroomanage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    /*
     * Method 01 : on 23/04/2012
     * Update by hnmtuan using normal event decalerations
     */
    private void jtblistofroomMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtblistofroomMouseClicked
        // TODO add your handling code here:
        try {
            if (phongChieus == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int selectedRow = jtblistofroom.getSelectedRow();
            Phongchieu selectedRoom = phongChieus.get(selectedRow);
            if (selectedRoom == null) {
                throw new Exception(ERR_SELECTED_ROOM_EMPTY);
            }
            selectedStateComponents();
            this.jtxtcodeid.setText(selectedRoom.getCodePhong());
            this.jtxtroomname.setText(selectedRoom.getTenPhong());
            this.jtxtquantitiesofseat.setText(selectedRoom.getSoLuongCho().toString());
            this.jtxtquantitiesofseatrow.setText(selectedRoom.getSoLuongHangGhe().toString());
            this.jcbroomstate.setSelectedIndex(selectedRoom.getTrangThai());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jtblistofroomMouseClicked

    private void jbtnupdateroomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnupdateroomActionPerformed
        // TODO add your handling code here:
        try {
            String rollAction = this.jbtnupdateroom.getText();
            // If update button is saving state
            if (rollAction.compareToIgnoreCase(LABEL_SAVE) == 0) {
                updateSuccessStateComponents();
            } else { // if update button is updating
                updateStateComponents();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jbtnupdateroomActionPerformed

    private void jbtncancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtncancelActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);

    }//GEN-LAST:event_jbtncancelActionPerformed

    private void jbtndeleteroomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtndeleteroomActionPerformed
        // TODO add your handling code here:
        try{
            int selectRow = jtblistofroom.getSelectedRow();
            Phongchieu pc = phongChieus.get(selectRow);
            pc.setTrangThai(0);
            boolean kq = PhongChieuDAO.updatePhongChieus(pc);
            if(kq == true){
                LoadDBJTable();
            }
            clearTextFields();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jbtndeleteroomActionPerformed

    private void jbtnresetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnresetActionPerformed
        // TODO add your handling code here:
        initStateComponents();
        clearTextFields();
    }//GEN-LAST:event_jbtnresetActionPerformed

    private void jbtnaddroomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnaddroomActionPerformed
        // TODO add your handling code here:
        try {
            String rollAction = this.jbtnaddroom.getText();
            // If update button is saving state
            if (rollAction.compareToIgnoreCase(LABEL_SAVE) == 0) {
                addSuccessStateComponents();
            } else { // if update button is updating
                addStateComponents();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_jbtnaddroomActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnaddroom;
    private javax.swing.JButton jbtncancel;
    private javax.swing.JButton jbtndeleteroom;
    private javax.swing.JButton jbtnreset;
    private javax.swing.JButton jbtnsearch;
    private javax.swing.JButton jbtnshowall;
    private javax.swing.JButton jbtnupdateroom;
    private javax.swing.JComboBox jcbroomstate;
    private javax.swing.JCheckBox jchbsearchbycodeid;
    private javax.swing.JCheckBox jchbsearchbyname;
    private javax.swing.JLabel jlbcodeid;
    private javax.swing.JLabel jlblistofrooms;
    private javax.swing.JLabel jlbquantitiesofseat;
    private javax.swing.JLabel jlbquantitiesofseatline;
    private javax.swing.JLabel jlbroomname;
    private javax.swing.JLabel jlbroomstate;
    private javax.swing.JLabel jlbsearchroom;
    private javax.swing.JPanel jpnroomanage;
    private javax.swing.JTable jtblistofroom;
    private javax.swing.JTextField jtxtcodeid;
    private javax.swing.JTextField jtxtquantitiesofseat;
    private javax.swing.JTextField jtxtquantitiesofseatrow;
    private javax.swing.JTextField jtxtroomname;
    private javax.swing.JTextField jtxttypethecodeid;
    private javax.swing.JTextField jtxttypethename;
    // End of variables declaration//GEN-END:variables
}
